package org.example.service.impl;

import org.example.client.CommityClient;
import org.example.mapper.WorksMapper;
import org.example.pojo.Users;
import org.example.pojo.Works;
import org.example.service.IWorksService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 作品表，存储用户发布的作品信息及相关属性 服务实现类
 * </p>
 *
 * @author zhx
 * @since 2025-01-17
 */
@Service
public class WorksServiceImpl extends ServiceImpl<WorksMapper, Works> implements IWorksService {
@Autowired
WorksMapper worksMapper;
    @Autowired
    private CommityClient commityClient;

    @Override
    public Works getAllWorks(Integer workId) {
        List<Users> usersList=commityClient.getAllUsers();
        HashMap<Integer, String> map = new HashMap<>();
        HashMap<Integer, String> map1 = new HashMap<>();
        for (Users user : usersList) {
            map.put(user.getUserId(),user.getNickname());
            map1.put(user.getUserId(),user.getAvatar());
        }
        Works works = worksMapper.getAllWorks(workId);
        works.setNickname(map.get(works.getUserId()));
        works.setAvatar(map1.get(works.getUserId()));
        return works;
    }

    @Override
    public void likesContent(Integer workId) {
        worksMapper.likesContent(workId);
    }

    @Override
    public void unlikesContent(Integer workId) {
        worksMapper.unlikesContent(workId);
    }

    @Override
    public void sharesContent(Integer workId) {
        worksMapper.sharesContent(workId);
    }

    @Override
    public void unsharesContent(Integer workId) {
        worksMapper.unsharesContent(workId);
    }
}
